﻿// *********************************************************************
// [DCOM Productions]
// [Copyright (C) DCOM Productions All rights reserved.]
// *********************************************************************

namespace BitFlex.Windows.Forms {
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

    /// <summary>
    /// The Windows Explorer TextBox
    /// </summary>
    [ToolboxBitmap(typeof(TextBox))]
    public sealed partial class ExplorerTextBox : System.Windows.Forms.TextBox {
        /// <summary>
        /// Instantiates a new instance of the BitFlex.Windows.Forms.ExplorerTextBox control
        /// </summary>
        public ExplorerTextBox() {
            InitializeComponent();
        }

        #region Platform Invoke

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr SendMessage(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam);

        #endregion

        #region Constants

        private const Int32 ECM_FIRST = 0x1500;
        private const Int32 EM_SETCUEBANNER = ECM_FIRST + 1;

        #endregion

        #region Properties

        private String m_CueText = String.Empty;
        /// <summary>
        /// Gets or Sets the cue text
        /// </summary>
        [
            Category("Appearance"),
            DefaultValue(""),
            Description("Gets or Sets the cue text")
        ]
        public String CueText {
            get {
                return m_CueText;
            }
            set {
                m_CueText = value;
                SetCueText();
            }
        }

        #endregion

        private void SetCueText() {
            SendMessage(Handle, EM_SETCUEBANNER, IntPtr.Zero, Marshal.StringToBSTR(CueText));
        }
    }
}